﻿using Controller.Utils;
using Controller.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Controller.Enum;

namespace ControllerManageServer.ActionModel.Aioi
{
    class AioiBaseActionModel : AioiActionModelAbstract
    {

        /// <summary>
        /// 模式数组
        /// </summary>
        /// <returns></returns>
        public override byte[] ModeArray()
        {
            List<byte> data = new List<byte>();
            data.AddRange(DefaultEncoding.GetBytes("m1"));
            data.AddRange(ByteUtils.BinStrToBytes(FactorScroll.BinValue + FactorColor.Value + FactorSeq.Value + FactorBuzzers.Value));
            data.AddRange(DefaultEncoding.GetBytes("m2"));
            data.AddRange(ByteUtils.BinStrToBytes(ConfirmScroll.BinValue + ConfirmColor.Value + ConfirmSeq.Value + ConfirmBuzzers.Value));
            data.AddRange(DefaultEncoding.GetBytes("m3"));
            data.AddRange(ByteUtils.BinStrToBytes(FnScroll.BinValue + FnColor.Value + FnSeq.Value + FnBuzzers.Value));
            data.AddRange(DefaultEncoding.GetBytes("m4"));
            //data.AddRange(ByteUtil.HexStrToBytes(ByteUtil.BinStrToHexStr("101000")));
            //                 填充+[a]+[b]+[c]
            data.AddRange(ByteUtils.BinStrToBytes("01" + FnDecrease.BinValue + FnKey.BinValue + ConfirmKey.BinValue));

            return data.ToArray();
        }

        /// <summary>
        /// 转换成动作模型
        /// </summary>
        /// <param name="iModel"></param>
        public override void ToActionModel(ActionPacketModel iModel)
        {
            FactorColor = GetLightColor(iModel.ControlModel.LightModel);// 亮灯颜色
            FactorBuzzers = GetDeviceBuzzer(iModel.ControlModel.OpenBuzzer);// 蜂鸣器
            FactorSeq = string.IsNullOrEmpty(iModel.ControlModel.Seq) || iModel.ControlModel.Seq.Length == 0 ? Bin.OFF : Bin.ON;// 是否显示

            ConfirmColor = GetLightColor(iModel.ControlModel.ConfirmLightModel);// 按Confirm后的亮灯颜色
            ConfirmBuzzers = GetDeviceBuzzer(iModel.ControlModel.ConfirmOpenBuzzer);// 按Confirm后的蜂鸣器
            ConfirmSeq = string.IsNullOrEmpty(iModel.ControlModel.ConfirmSeq) || iModel.ControlModel.ConfirmSeq.Length == 0 ? Bin.OFF : Bin.ON;// 按Confirm后是否显示
            ConfirmKey = iModel.ControlModel.IsUsedConfirm ? Func.USED : Func.NOT_USED;// 是否使用Confirm键
            if (iModel.LabelType == EquipmentLabelTypeEnum.AIOI_LABEL_MWU2414)
            {
                if (iModel.ControlModel.IsScroll) FactorScroll = Scroll.ON;
                if (iModel.ControlModel.ConfirmIsScroll) ConfirmScroll = Scroll.ON;
            }
        }

    }
}
